﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jzy.Core.Common;
using FortuneHeavenCommon.DataMap;

namespace FortuneHeavenDAL
{
    public class UserSpreadDAL : BaseDAL
    {
        public List<UserSpread> GetUserSpreads(int page, int size, int type ,int userid)
        {
            string sql = @"select * from (
select [ID],[UserID],[FromUserID],[RechargeType],[Remark],[Value],[DateTime],[FromUserName]
,ROW_NUMBER() OVER(ORDER BY ID DESC) ROW 
from UserSpread where RechargeType =@p0 and UserID =@p1) FF
 WHERE FF.ROW BETWEEN  @p2 AND @p3"; ;
            List<UserSpread> list = dbOper.Query<UserSpread>(sql, type, userid, size * (page - 1) + 1, size * page);
            return list;
        }
        public int GetTotalSize(int type, int userid)
        {
            string sql = @"select count(id) from UserSpread where RechargeType =@p0 and UserID =@p1";
            return dbOper.GetScalar<int>(sql, type, userid);
        }




        public List<SpreadListSta> GetUserSpreadsSta(int page, int size, string acount)
        {
            string condition = "where A.IsSpread=1 ";
            if (!string.IsNullOrEmpty(acount))
            {
                condition = condition + " and B.Accounts in ('" + acount + "')";
            }

            string sql = @"select * from (select B.GameID,B.Accounts,B.RegisterDate,B.LastLogonDate,B.RegisterIP,A.SpreadValue,
(select COUNT(UserID) from  QPGameUserDB..AccountsInfo t where  t.SpreaderID =B.UserID )SpreadUserCount,
ROW_NUMBER() OVER(ORDER BY B.UserID DESC) ROW 
 from UserInfor A inner join QPGameUserDB..AccountsInfo B on A.UserID = B.UserID
{0}) FF
 WHERE FF.ROW BETWEEN  @p0 AND @p1"; ;
            List<SpreadListSta> list = dbOper.Query<SpreadListSta>(string.Format(sql, condition), size * (page - 1) + 1, size * page);
            return list;
        }
        public int GetTotalSizeSta( string acount)
        {
            string condition = "where A.IsSpread=1 ";
            if (!string.IsNullOrEmpty(acount))
            {
                condition = condition + " and B.Accounts in ('" + acount + "')";
            }

            string sql = @"select count(Accounts) from UserInfor A inner join QPGameUserDB..AccountsInfo B on A.UserID = B.UserID {0}";
            return dbOper.GetScalar<int>(string.Format(sql, condition));
        }
    }
}
